//------------------------------------------------------------------------------ 
// <copyright file="JDroppable.cs" company="Fm Computer">
//     Copyright (c) Fm Computer di Menatti Fulvia.  All rights reserved.
// </copyright>
//----------------------------------------------------------------------------- 
namespace FmjQuery
{
    using System.ComponentModel;
    using System.Text;
    using System.Web.UI;

    /// <summary>
    /// Droppable extender
    /// </summary>
    [ToolboxData("<{0}:JDroppable runat=server Tolerance=intersect />")]
    [DefaultProperty("TargetControlID")]
    public class JDroppable : JQueryExtendControl
    {
        #region Costruct
        /// <summary>
        /// Initializes a new instance of the JDroppable class.
        /// </summary>
        public JDroppable()
        {
            this.IsRenderControl = false;
        }
        #endregion

        #region Property

        /// <summary>
        /// Gets or sets All draggables that match the selector will be accepted. If a function is specified, the function will be called for each draggable on the page (passed as the first argument to the function), to provide a custom filter
        /// </summary>
        public string Accept 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets or sets the class will be added to the droppable while an acceptable draggable is being dragged
        /// </summary>
        public string ActiveClass 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets or sets will prevent the ui-droppable class from being added. This may be desired as a performance optimization when calling
        /// </summary>
        public string AddClasses
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a value indicating whether event propagation on nested droppables
        /// </summary>
        public bool Greedy 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets or sets the class will be added to the droppable while an acceptable draggable is being hovered
        /// </summary>
        public string HoverClass 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets or sets Used to group sets of draggable and droppable items, in addition to droppable's accept option. A draggable with the same scope value as a droppable will be accepted
        /// </summary>
        public string Scope 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets or sets specifies which mode to use for testing whether a draggable is 'over' a droppable
        /// </summary>
        [DefaultValue(typeof(DropToleranceType), "intersect")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public DropToleranceType Tolerance
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets name of client function that call when any time an accepted draggable starts dragging
        /// </summary>
        public string OnClientActive 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets or sets name of client function that call when any time an accepted draggable stops dragging
        /// </summary>
        public string OnClientDeactive 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets or sets name of client function that call when an accepted draggable is dragged 'over' (within the tolerance of) this droppable
        /// </summary>
        public string OnClientOver 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets or sets name of client function that call when an accepted draggable is dragged out (within the tolerance of) this droppable
        /// </summary>
        public string OnClientOut 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets or sets name of client function that call when an accepted draggable is dropped 'over' (within the tolerance of) this droppable
        /// </summary>
        public string OnClientDrop 
        { 
            get; 
            set; 
        }
        #endregion

        #region Overrides of JQueryExtendControl
        /// <summary>
        /// Return list of webResource
        /// </summary>
        /// <returns>web resources</returns>
        public override JWebSources GetResources()
        {
            return null;
        }

        /// <summary>
        /// Gets list of css image resources
        /// </summary>
        /// <returns>list of images</returns>
        public override CssResources GetCssResources()
        {
            return null;
        }

        /// <summary>
        /// Gets list of client nameSpace
        /// </summary>
        /// <returns>list of namespace</returns>
        public override ClientNameSpaces GetClientNameSpace()
        {
            return null;
        }

        /// <summary>
        /// Create jQuery control
        /// </summary>
        public override void CreateJControl()
        {
            if (this.Enabled)
            {
                this.Manager.Droppable = true;

                // create script
                StringBuilder builder = new StringBuilder();

                builder.AppendFormat("$('#{0}').droppable(", this.TargetControlClientID);
                builder.Append("{");
                builder.AppendFormat("tolerance: '{0}'", this.Tolerance);

                if (!string.IsNullOrEmpty(this.Accept))
                {
                    builder.AppendFormat(",accept: '{0}'", this.Accept);
                }

                if (!string.IsNullOrEmpty(this.ActiveClass))
                {
                    builder.AppendFormat(",activeClass: '{0}'", this.ActiveClass);
                }

                if (!string.IsNullOrEmpty(this.AddClasses))
                {
                    builder.AppendFormat(",addClasses: '{0}'", this.AddClasses);
                }

                if (this.Greedy)
                {
                    builder.Append(",greedy: true");
                }

                if (!string.IsNullOrEmpty(this.HoverClass))
                {
                    builder.AppendFormat(",hoverClass: '{0}'", this.HoverClass);
                }

                if (!string.IsNullOrEmpty(this.Scope))
                {
                    builder.AppendFormat(",scope: '{0}'", this.Scope);
                }

                if (!string.IsNullOrEmpty(this.OnClientActive))
                {
                    builder.AppendFormat(",activate: {0}", this.OnClientActive);
                }

                if (!string.IsNullOrEmpty(this.OnClientDeactive))
                {
                    builder.AppendFormat(",deactive: {0}", this.OnClientDeactive);
                }

                if (!string.IsNullOrEmpty(this.OnClientOver))
                {
                    builder.AppendFormat(",over: {0}", this.OnClientOver);
                }

                if (!string.IsNullOrEmpty(this.OnClientOver))
                {
                    builder.AppendFormat(",out: {0}", this.OnClientOut);
                }

                if (!string.IsNullOrEmpty(this.OnClientDrop))
                {
                    builder.AppendFormat(",drop: {0}", this.OnClientDrop);
                }

                builder.Append("});");

                Utility.RegisterStartUpScript(this.Page, string.Concat("Drop_", this.ClientID), builder.ToString());
            }
        }
        #endregion
    }
}